<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%;"
  >
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">
                添加部门

              </el-dropdown-item>
              <el-dropdown-item v-if="!root" command="exit">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { reqGetDepartments } from '@/api/departments'

export default {

  props: {
    root: {
      type: Boolean,
      required: false
    },
    nodeData: {
      type: Object,
      required: true
    }

  },
  data() {
    return {
      isShow: true
    }
  },
  methods: {
    handleCommand(str) {
      // console.log(str, '被点击了')
      if (str === 'add') {
        console.log('添加操作')
        console.log(this.nodeData, 999999999999)
        this.$emit('adddept', this.nodeData)
        // console.log(this.nodeData, 99999999)
      }
      if (str === 'exit') {
        console.log('编辑')
      }
      if (str === 'del') {
        console.log('删除')
        this.$confirm('此操作将永久删除数据', '温馨提示').then(async() => {
          const res = await reqGetDepartments(this.nodeData.id)
          this.$emit('del-dept')
          console.log(res)
          this.$message.success('删除成功')
        }).catch(() => {
          // console.log('');
          this.$message.error('取消操作')
        })
      }
    },
    adddept() {
      this.isShow = !this.isShow
    }
    // handleClose() {
    //   this.isShow = false
    // }
  }
}
</script>

<style>

</style>
